/************************************************************************
                        Data.h.cpp - Copyright asaf
**************************************************************************/

#include "Data.h"
// Constructors/Destructors
//  

Data::Data ( ) {
}

Data::~Data ( ) { }
 
// Methods
auto_ptr<Reply> Data::checkLogin (const Request &request) {
	Person p(request.getParameter("ID"));
	list< Person >::iterator iter=find(m_personList.begin(),m_personList.end(),p);
	if(iter==m_personList.end())return new Reply(LOGIN_FAILED);
	ReplyData *r=new ReplyData(LOGIN_SUCCESS);
	r->addParameter("PERMISSION",USER_PERMISSION_LEVEL_TO_STRING(iter->getPermission()));
	r->addParameter("FirstName",iter->getFirstName());
	r->addParameter("LastName",iter->getLastName());
	return r;
}

auto_ptr<Reply> Data::personLogout (const Request &request) {
	return new Reply(LOGOUT_SUCCESS);
}

auto_ptr<Reply> Data::addNewPerson (const Request &request) {
	Person p(request.getParameter("ID"),request.getParameter("FirstName"),
		request.getParameter("LastName"),
		USER_TYPE_TO_INT(request.getParameter("Type")),
		USER_PERMISSION_TO_INT(request.getParameter("Permission")),
		stringToInt("0" + request.getParameter("Semester")),
		request.getParameter("Address"),
		stringToInt(request.getParameter("BirthDay")),
		stringToInt(request.getParameter("BirthMonth")),
		stringToInt(request.getParameter("BirthYear")));
	list< Person >::iterator iter=find(m_personList.begin(),m_personList.end(),p);
	if(iter!=m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"PERSON_ALLREADY_IN_DB");
	try{m_personList.push_back(p);}
	catch(...){m_personList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::addNewCourse (const Request &request) {
	Course c(request.getParameter("ID"),request.getParameter("CourseName"),stringToInt("0" + request.getParameter("Semester")));
	list< Course >::iterator c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if(c_iter!=m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_ALLREADY_IN_DB");
	Person p1(request.getParameter("LectID"));
	list< Person >::iterator p1_iter=find(m_personList.begin(),m_personList.end(),p1);
	if (p1_iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURER1_NOT_FOUND");
	Person p2(request.getParameter("LectID2"));
	list< Person >::iterator p2_iter=find(m_personList.begin(),m_personList.end(),p2);
	if (p2_iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURER2_NOT_FOUND");
	try{m_courseList.push_back(c);}
	catch(...){m_courseList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if (c_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_NOT_FOUND");
	int start_hour,end_hour,semester,weekday,maxAtt;
	start_hour=stringToInt(request.getParameter("Start_Hour"));
	end_hour=stringToInt(request.getParameter("End_Hour"));
	semester=stringToInt(request.getParameter("Semester"));
	weekday=stringToInt(request.getParameter("Weekday"));
	maxAtt=stringToInt(request.getParameter("MaxAttendants"));
	int start_hour2,end_hour2,weekday2,maxAtt2;
	start_hour2=stringToInt(request.getParameter("Start_Hour2"));
	end_hour2=stringToInt(request.getParameter("End_Hour2"));
	weekday2=stringToInt(request.getParameter("Weekday2"));
	maxAtt2=stringToInt(request.getParameter("MaxAttendants2"));
	CourseLectTimeSemeter clts(*c_iter,*p1_iter,maxAtt);
	clts.getTime().setStartingHour(start_hour);
	clts.getTime().setEndingHour(end_hour);
	clts.getTime().setSemester(semester);
	clts.getTime().setWeekday(weekday);
	CourseLectTimeSemeter clts2(*c_iter,*p2_iter,maxAtt2);
	clts2.getTime().setStartingHour(start_hour2);
	clts2.getTime().setEndingHour(end_hour2);
	clts2.getTime().setSemester(semester);
	clts2.getTime().setWeekday(weekday2);
	try{m_courseLectList.push_back(clts);}
	catch(...){m_courseLectList.pop_back();m_courseList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	try{m_courseLectList.push_back(clts2);}
	catch(...){m_courseLectList.pop_back();m_courseLectList.pop_back();m_courseList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	return new Reply(DB_REQUEST_SUCCESS);
}
auto_ptr<Reply> Data::deletePerson (const Request &request) {
	Person p(request.getParameter("ID"));
	list <StudentCourse>::iterator iter;
	list <StudentCourse>::iterator tmpiter;
	for(iter=m_studentCourseList.begin();iter!=m_studentCourseList.end();)
	{
		if((*iter).getStudentRef()==p || (*iter).getCltsRef().getLecturerRef()==p)
		{
			tmpiter=iter;
			tmpiter++;
			m_studentCourseList.erase(iter);
			iter=tmpiter;
		}
		else iter++;
	}

	list <CourseLectTimeSemeter>::iterator iter2;
	list <CourseLectTimeSemeter>::iterator tmpiter2;
	for(iter2=m_courseLectList.begin();iter2!=m_courseLectList.end();iter2++)
	{
		if(iter2->getLecturerRef()==p)
		{
			tmpiter2=iter2;
			tmpiter2++;
			m_courseLectList.erase(iter2);
			iter2=tmpiter2;
		}
	}

	m_personList.remove(p);
	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::deleteCourse (const Request &request) {
	Course c(request.getParameter("ID"));
	
	list <CoursePreRequisite>::iterator iter3;
	list <CoursePreRequisite>::iterator tmpiter3;
	for(iter3=m_coursePreRequisiteList.begin();iter3!=m_coursePreRequisiteList.end();)
	{
		if(iter3->getCourseRef()==c || iter3->getPreRequisite()==c)
		{
			tmpiter3=iter3;
			tmpiter3++;
			m_coursePreRequisiteList.erase(iter3);
			iter3=tmpiter3;
		}
		else iter3++;
	}
	
	list <StudentCourse>::iterator iter;
	list <StudentCourse>::iterator tmpiter;
	for(iter=m_studentCourseList.begin();iter!=m_studentCourseList.end();)
	{
		if((*iter).getCltsRef().getCourseRef()==c)
		{
			tmpiter=iter;
			tmpiter++;
			m_studentCourseList.erase(iter);
			iter=tmpiter;
		}
		else iter++;
	}

	list <CourseLectTimeSemeter>::iterator iter2;
	list <CourseLectTimeSemeter>::iterator tmpiter2;
	for(iter2=m_courseLectList.begin();iter2!=m_courseLectList.end();iter2++)
	{
		if(iter2->getCourseRef()==c)
		{
			tmpiter2=iter2;
			tmpiter2++;
			m_courseLectList.erase(iter2);
			iter2=tmpiter2;
		}
	}
 	m_courseList.remove(c);
	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::editPerson (const Request &request) {
	Person p(request.getParameter("ID"));
	list< Person >::iterator iter=find(m_personList.begin(),m_personList.end(),p);
	if(iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"PERSON_NOT_FOUND");
	if(request.getParameter("FirstName")!="")iter->setFirstName(request.getParameter("FirstName"));
	if(request.getParameter("LastName")!="")iter->setLastName(request.getParameter("LastName"));
	if(request.getParameter("Address")!="")iter->setAddress(request.getParameter("Address"));
	if(request.getParameter("BirthDay")!="")iter->setBirthDay(stringToInt("0"+request.getParameter("BirthDay")));
	if(request.getParameter("BirthMonth")!="")iter->setBirthMonth(stringToInt("0"+request.getParameter("BirthMonth")));
	if(request.getParameter("BirthYear")!="")iter->setBirthYear(stringToInt("0"+request.getParameter("BirthYear")));
	if(request.getParameter("Type")!="")iter->setType(USER_TYPE_TO_INT( request.getParameter("Type")));
	if(request.getParameter("Permission")!="")iter->setPermission(USER_PERMISSION_TO_INT(request.getParameter("Permission")));
	if(request.getParameter("Semester")!="")iter->setSemester(stringToInt("0" + request.getParameter("Semester")));
	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::registerStudentCourse (const Request &request) {
	string pID=request.getParameter("StudentID");
	Person p(request.getParameter("StudentID"));
	Person l(request.getParameter("LectID"));
	Course c(request.getParameter("CourseID"));
	int start_hour,end_hour,semester,weekday,maxAtt;
	start_hour=stringToInt(request.getParameter("Start_Hour"));
	end_hour=stringToInt(request.getParameter("End_Hour"));
	semester=stringToInt(request.getParameter("Semester"));
	weekday=stringToInt(request.getParameter("Weekday"));
	maxAtt=0;//stringToInt(request.getParameter("MaxAttendants"));
	list< Person >::iterator p_iter=find(m_personList.begin(),m_personList.end(),p);
	if(p_iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"STUDENT_NOT_FOUND");
	list< Person >::iterator l_iter=find(m_personList.begin(),m_personList.end(),l);
	if(l_iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURER_NOT_FOUND");
	list< Course >::iterator c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if(c_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_NOT_FOUND");
	CourseLectTimeSemeter clts(*c_iter,*l_iter,maxAtt);
	clts.getTime().setStartingHour(start_hour);
	clts.getTime().setEndingHour(end_hour);
	clts.getTime().setSemester(semester);
	clts.getTime().setWeekday(weekday);
	list <CourseLectTimeSemeter>::iterator clts_iter=find(m_courseLectList.begin(),m_courseLectList.end(),clts);
	if(clts_iter==m_courseLectList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURE_NOT_FOUND");
	if(clts_iter->isFull())return new ReplyData(DB_REQUEST_FAIL,"COURSE_FULL");
	if (p_iter->getSemester()!=c_iter->getSemester()) return new ReplyData(DB_REQUEST_FAIL,"USER_INVALID_SEMESTER");
	if(!checkPrerequisits(*p_iter,*c_iter))return new ReplyData(DB_REQUEST_FAIL,"PREREQUISITS_NOT_MET");
		 StudentCourse sc(*p_iter,*clts_iter,stringToInt(request.getParameter("Completed")));
	list <StudentCourse>::iterator sc_iter2;
	for (sc_iter2=m_studentCourseList.begin();sc_iter2!=m_studentCourseList.end();sc_iter2++)
	{
		if((*sc_iter2).getStudentRef().getID()!=pID)continue;
		if((*sc_iter2)==sc)return new ReplyData(DB_REQUEST_FAIL,"STUDENT_ALLREADY_REGISTERED_TO_COURSE");
		if((*sc_iter2).getCltsRef().getTime().isAcademicTimeOverlapping(clts.getTime()))
			 return new ReplyData(DB_REQUEST_FAIL,"STUDENT_COURSE_OVERLAPPING");
	} 
	try{m_studentCourseList.push_back(sc);}
	catch(...){m_studentCourseList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	clts_iter->addAttendant();
	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::setStudentCourse_Completed (const Request &request) {
	Person p(request.getParameter("StudentID"));
	Person l(request.getParameter("LectID"));
	Course c(request.getParameter("CourseID"));
	int start_hour,end_hour,semester,weekday,maxAtt;
	start_hour=0;end_hour=0;semester=0;weekday=0;maxAtt=0;
	CourseLectTimeSemeter clts(c,l,maxAtt);
	clts.getTime().setStartingHour(start_hour);
	clts.getTime().setEndingHour(end_hour);
	clts.getTime().setSemester(semester);
	clts.getTime().setWeekday(weekday);
	StudentCourse sc(p,clts,stringToInt(request.getParameter("Completed")));
	list <CourseLectTimeSemeter>::iterator clts_iter;
	int recordsChanged=0;
	for (clts_iter=m_courseLectList.begin();clts_iter!=m_courseLectList.end();clts_iter++)
		if ((*clts_iter)==clts)
		{
			(sc.getCltsRef().getTime())=(*clts_iter).getTime();
			list< StudentCourse >::iterator sc_iter=find(m_studentCourseList.begin(),m_studentCourseList.end(),sc);
			if(sc_iter==m_studentCourseList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURE_NOT_FOUND");
			(*sc_iter).setComplete(stringToInt(request.getParameter("Completed")));
			recordsChanged++;
		}
		if (recordsChanged>0)return new Reply(DB_REQUEST_SUCCESS);
		return new ReplyData(DB_REQUEST_FAIL,"LECTURE_NOT_FOUND");
}

auto_ptr<Reply> Data::assignCourseLecturerTime (const Request &request) {
	Person p(request.getParameter("LectID"));
	Course c=(request.getParameter("CourseID"));
	int start_hour,end_hour,semester,weekday,maxAtt;
	start_hour=stringToInt(request.getParameter("Start_Hour"));
	end_hour=stringToInt(request.getParameter("End_Hour"));
	semester=stringToInt(request.getParameter("Semester"));
	weekday=stringToInt(request.getParameter("Weekday"));
	maxAtt=stringToInt(request.getParameter("MaxAttendants"));
	list< Person >::iterator p_iter=find(m_personList.begin(),m_personList.end(),p);
	if(p_iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"LECTURER_NOT_FOUND");
	if(p_iter->getType()!=TYPE_LECTURER) return new ReplyData(DB_REQUEST_FAIL,"INVALID_USER_TYPE");
	list< Course >::iterator c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if(c_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_NOT_FOUND");
	CourseLectTimeSemeter clts(*c_iter,*p_iter,maxAtt);
	clts.getTime().setStartingHour(start_hour);
	clts.getTime().setEndingHour(end_hour);
	clts.getTime().setSemester(semester);
	clts.getTime().setWeekday(weekday);
	list <CourseLectTimeSemeter>::iterator clts_iter=find(m_courseLectList.begin(),m_courseLectList.end(),clts);
	if(clts_iter!=m_courseLectList.end()&&
		(((start_hour>=clts_iter->getTime().getStartingHour())&&
		(start_hour<clts_iter->getTime().getEndingHour()))||
		((end_hour>clts_iter->getTime().getStartingHour())&&
		(end_hour<clts_iter->getTime().getEndingHour())))&&
		(semester==clts_iter->getTime().getSemester())&&
		(weekday==clts_iter->getTime().getWeekday()))
		return new ReplyData(DB_REQUEST_FAIL,"LECTURE_ALLREADY_IN_DB");
	try{m_courseLectList.push_back(clts);}
	catch(...){m_courseLectList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}

	return new Reply(DB_REQUEST_SUCCESS);
}

auto_ptr<Reply> Data::getAllCourses ( ) {
	//this will return all courses, sorted by semester.
	//m_courseList.sort(sortPredicateBySemester);
	//this will never work becouse of a known bug in vc6 stl.
	vector<Course>s;
	auto_ptr<Reply>replydata(new ReplyData(DB_REQUEST_SUCCESS));
	list<Course>::iterator l_iter;
	for (l_iter=m_courseList.begin();l_iter!=m_courseList.end();l_iter++)
	{
		try{s.push_back(*l_iter);}
		catch(...){s.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	}
	sort(s.begin(),s.end(),Course::sortPredicateBySemester);
	vector<Course>::iterator v_iter;
	for (v_iter=s.begin();v_iter!=s.end();v_iter++)
	{
		replydata->addParameter("CourseName",(*v_iter).getCourseName());
		replydata->addParameter("ID",(*v_iter).getID());
		replydata->addParameter("Semester",intToString((*v_iter).getSemester()));
	}
	return replydata;
}

/**
 * @return Reply
 * @param  course
 */
auto_ptr<Reply> Data::getCourseData (const Request &request) {
	Course c(request.getParameter("ID"));
	list< Course >::iterator c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if(c_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_NOT_FOUND");
	auto_ptr<Reply>replydata(new ReplyData(DB_REQUEST_SUCCESS));
	replydata->addParameter("CourseName",(*c_iter).getCourseName());
	replydata->addParameter("ID",(*c_iter).getID());
	list<Course>preRequisitsList=getPreRequisitCourses(*c_iter);
	for(c_iter=preRequisitsList.begin();c_iter!=preRequisitsList.end();c_iter++)
	{
		replydata->addParameter("PreRequisite",(*c_iter).getCourseName());
	}
	list <CourseLectTimeSemeter>::iterator clts_iter;
	for (clts_iter=m_courseLectList.begin();clts_iter!=m_courseLectList.end();clts_iter++)
		if ((*clts_iter)==c)
		{
			replydata->addParameter("Lecturer FName",(*clts_iter).getLecturerRef().getFirstName());
			replydata->addParameter("Lecturer LName",(*clts_iter).getLecturerRef().getLastName());
			replydata->addParameter("Start_Hour",intToString((*clts_iter).getTime().getStartingHour()));
			replydata->addParameter("End_Hour",intToString((*clts_iter).getTime().getEndingHour()));
			replydata->addParameter("day",intToString((*clts_iter).getTime().getWeekday()));
			replydata->addParameter("Semester",intToString((*clts_iter).getTime().getSemester()));
			replydata->addParameter("Free Places",intToString((*clts_iter).freePlaces()));
		}
	return replydata;
}

/**
 * @return Reply
 * @param  person
 */
auto_ptr<Reply> Data::getPersonData (const Request &request) {
	Person p(request.getParameter("ID"));
	list< Person >::iterator iter=find(m_personList.begin(),m_personList.end(),p);
	if(iter==m_personList.end())return new ReplyData(DB_REQUEST_FAIL,"PERSON_NOT_FOUND");
	auto_ptr<Reply>replydata(new ReplyData(DB_REQUEST_SUCCESS));
	replydata->addParameter("ID",(*iter).getID());
	replydata->addParameter("FirstName",(*iter).getFirstName());
	replydata->addParameter("LastName",(*iter).getLastName());
	replydata->addParameter("Type",USER_TYPE_TO_STRING((*iter).getType()));
	replydata->addParameter("Permission",USER_PERMISSION_LEVEL_TO_STRING((*iter).getPermission()));
	replydata->addParameter("Address",(*iter).getAddress());
	replydata->addParameter("BirthDay",intToString((*iter).getBirthDay()));
	replydata->addParameter("BirthMonth",intToString((*iter).getBirthMonth()));
	replydata->addParameter("BirthYear",intToString((*iter).getBirthYear()));
	replydata->addParameter("Current Semester",intToString((*iter).getSemester()));
	list< StudentCourse >::iterator sc_iter;
	for(sc_iter=m_studentCourseList.begin();sc_iter!=m_studentCourseList.end();sc_iter++)
		if(((*sc_iter)==p)&&((*sc_iter).getCltsRef().getTime().getSemester()==(*iter).getSemester()))
		{
			replydata->addParameter("Course Name",(*sc_iter).getCltsRef().getCourseRef().getCourseName());
			replydata->addParameter("Lecturer FName",(*sc_iter).getCltsRef().getLecturerRef().getFirstName());
			replydata->addParameter("Lecturer LName",(*sc_iter).getCltsRef().getLecturerRef().getLastName());
			replydata->addParameter("Course Semester",intToString((*sc_iter).getCltsRef().getTime().getSemester()));
		}
	return replydata;
}

auto_ptr<Reply> Data::getCoursesForSemester (const Request &request) {
	auto_ptr<Reply> replydata;
	int semester=stringToInt(request.getParameter("Semester"));
	list<Course>::iterator c_iter;
	int recordsaffected=0;
	for(c_iter=m_courseList.begin();c_iter!=m_courseList.end();c_iter++)
		if((*c_iter).getSemester()==semester)
		{
			if(replydata.get()==NULL)replydata=auto_ptr<Reply>(new ReplyData(DB_REQUEST_SUCCESS));
			replydata->addParameter("CourseName",(*c_iter).getCourseName());
			replydata->addParameter("ID",(*c_iter).getID());
			replydata->addParameter("Semester",intToString((*c_iter).getSemester()));
			recordsaffected++;
		}
	if (recordsaffected==0)return new ReplyData(DB_REQUEST_FAIL,"NO_RECOREDS_FOUND");
	return replydata;
}

auto_ptr<Reply> Data::addPreRequisitCourse(const Request &request) {
	request.getParameter("CourseID");
	request.getParameter("PreRequisitCourseID");
	Course c(request.getParameter("CourseID"));
	list< Course >::iterator c_iter=find(m_courseList.begin(),m_courseList.end(),c);
	if(c_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"COURSE_NOT_FOUND");
	Course preRequisit(request.getParameter("PreRequisitCourseID"));
	list< Course >::iterator pre_iter=find(m_courseList.begin(),m_courseList.end(),preRequisit);
	if(pre_iter==m_courseList.end())return new ReplyData(DB_REQUEST_FAIL,"PREREQUISIT_NOT_FOUND");
	CoursePreRequisite cpr(*c_iter,*pre_iter);
	try{m_coursePreRequisiteList.push_back(cpr);}
	catch(...){m_coursePreRequisiteList.pop_back();return new ReplyData(DB_REQUEST_FAIL,"MEMORY_ALLOCATION_ERROR");}
	return new Reply(DB_REQUEST_SUCCESS);
}

list <Course> Data::getPreRequisitCourses(const Course &course)
{
	list<Course>preRequisitsList;
	list<CoursePreRequisite>::iterator cpr_iter;
	for(cpr_iter=m_coursePreRequisiteList.begin();cpr_iter!=m_coursePreRequisiteList.end();cpr_iter++)
	{
		if((*cpr_iter).getCourseRef()==course)
		{
			try{preRequisitsList.push_back((*cpr_iter).getPreRequisite());}
			catch(...){preRequisitsList.pop_back();}
		}
	}
	return preRequisitsList;
}

list <Course> Data::getCompletedCourses(const Person &person)
{
	int i=0;
	list<Course>completedCourses;
	list< StudentCourse >::iterator sc_iter;
	for(sc_iter=m_studentCourseList.begin();sc_iter!=m_studentCourseList.end();sc_iter++)
	{
		if(((*sc_iter)==person)&&((*sc_iter).getComplete()==true))
		{
			try{completedCourses.push_back((*sc_iter).getCltsRef().getCourseRef());}
			catch(...){completedCourses.pop_back();}
		}
	}
	return completedCourses;
}



bool Data::checkPrerequisits(const Person &person,const Course &course)
{
	list<Course>::iterator completed_iter;
	list<Course>::iterator prerequisits_iter;
	list<Course>preRequisitsList=getPreRequisitCourses(course);
	list<Course>completedCourses=getCompletedCourses(person);
	for(prerequisits_iter=preRequisitsList.begin();prerequisits_iter!=preRequisitsList.end();prerequisits_iter++)
	{	completed_iter=find(completedCourses.begin(),completedCourses.end(),*prerequisits_iter);
		if(completed_iter==completedCourses.end())return false;
	}
	return true;
}